Ext.define('AppMvc.controller.WebController', {
    extend: 'Ext.app.Controller',
        //将Viewport.js添加到控制器
    views: ['Viewport','MenuTree','WebTabPanel'],
    
    refs: [
        {
            ref: 'webtabpanel',
            selector: 'webtabpanel'
        }
    ],
    
    //通过init函数来监听视图事件，控制视图与控制器的交互
    init: function() {
        //init函数通过this.control来负责监听
        this.control({
             //被监听的组件的别名
            'menutree': {
                //监听鼠标点击事件，点击后调用openTab方法
                itemclick: this.openTab
            }
        });
    },
    openTab:function(me, record, item, index, e, eOpts){
    	var classData = record.raw;
    	if(record.raw.menuClass){
    		var tabId = 'tab_'+classData.id;
    		var menuClass = record.raw.menuClass;
	    	var childPanel = Ext.create(menuClass);
	    	
	    	//查询此菜单是否已经打开,如果没打开则新建,已打开则激活
	    	if(Ext.ComponentQuery.query('#'+tabId).length==0){
	    		//添加到主页中
		    	this.getWebtabpanel().add({
		    		id:tabId,
		    		title:classData.text,
		    		layout:'fit',
		    		items:childPanel,
		    		closable:true
		    	});
	    	}
	    	this.getWebtabpanel().setActiveTab(tabId);
    	}
    }
});
